package com.sakura;

import com.sakura.bean.Person;
import com.sakura.config.MainConfig;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Sakura
 * @Date 2023-02-20 18:02
 */
public class MainTest {
    public static void main(String[] args) {

        //1.读取配置文件
//        ClassPathXmlApplicationContext xmlApplicationContext
//                =new ClassPathXmlApplicationContext("beans.xml");
//        Person person = (Person) xmlApplicationContext.getBean("person");
//        System.out.println("person = " + person);

        //2.读取配置类
        AnnotationConfigApplicationContext configApplicationContext
                = new AnnotationConfigApplicationContext(MainConfig.class);

        Person bean = configApplicationContext.getBean(Person.class);
        System.out.println("bean = " + bean);

        String[] beanNamesForType = configApplicationContext.getBeanNamesForType(Person.class);
        for (String name : beanNamesForType) {
            System.out.println("name = " + name);//person11
        }

    }
}
